<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: cv::DataType&lt; _Tp &gt; Class Template Reference</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d2/d75/namespacecv.html">cv</a></li><li class="navelem"><a class="el" href="../../d0/d3a/classcv_1_1DataType.html">DataType</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">cv::DataType&lt; _Tp &gt; Class Template Reference<div class="ingroups"><a class="el" href="../../d0/de1/group__core.html">Core functionality</a> &raquo; <a class="el" href="../../dc/d84/group__core__basic.html">Basic structures</a></div></div>  </div>
</div><!--header-->
<div class="contents">

<p>Template "trait" class for OpenCV primitive data types.  
 <a href="../../d0/d3a/classcv_1_1DataType.html#details">More...</a></p>

<p><code>#include &lt;opencv2/core/traits.hpp&gt;</code></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h3>template&lt;typename _Tp&gt;<br />
class cv::DataType&lt; _Tp &gt;</h3>

<p>Template "trait" class for OpenCV primitive data types. </p>
<dl class="section note"><dt>Note</dt><dd>Deprecated. This is replaced by "single purpose" traits: traits::Type and traits::Depth</dd></dl>
<p>A primitive OpenCV data type is one of unsigned char, bool, signed char, unsigned short, signed short, int, float, double, or a tuple of values of one of these types, where all the values in the tuple have the same type. Any primitive type from the list can be defined by an identifier in the form CV_&lt;bit-depth&gt;{U|S|F}C(&lt;number_of_channels&gt;), for example: uchar CV_8UC1, 3-element floating-point tuple CV_32FC3, and so on. A universal OpenCV structure that is able to store a single instance of such a primitive data type is <a class="el" href="../../d6/dcf/classcv_1_1Vec.html" title="Template class for short numerical vectors, a partial case of Matx. ">Vec</a>. Multiple instances of such a type can be stored in a std::vector, <a class="el" href="../../d3/d63/classcv_1_1Mat.html" title="n-dimensional dense array class ">Mat</a>, <a class="el" href="../../df/dfc/classcv_1_1Mat__.html" title="Template matrix class derived from Mat. ">Mat_</a>, <a class="el" href="../../dd/da9/classcv_1_1SparseMat.html" title="The class SparseMat represents multi-dimensional sparse numerical arrays. ">SparseMat</a>, <a class="el" href="../../d7/d8a/classcv_1_1SparseMat__.html" title="Template sparse n-dimensional array class derived from SparseMat. ">SparseMat_</a>, or any other container that is able to store <a class="el" href="../../d6/dcf/classcv_1_1Vec.html" title="Template class for short numerical vectors, a partial case of Matx. ">Vec</a> instances.</p>
<p>The <a class="el" href="../../d0/d3a/classcv_1_1DataType.html" title="Template &quot;trait&quot; class for OpenCV primitive data types. ">DataType</a> class is basically used to provide a description of such primitive data types without adding any fields or methods to the corresponding classes (and it is actually impossible to add anything to primitive C/C++ data types). This technique is known in C++ as class traits. It is not <a class="el" href="../../d0/d3a/classcv_1_1DataType.html" title="Template &quot;trait&quot; class for OpenCV primitive data types. ">DataType</a> itself that is used but its specialized versions, such as: </p><div class="fragment"><div class="line"><span class="keyword">template</span>&lt;&gt; <span class="keyword">class </span>DataType&lt;<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a>&gt;</div><div class="line">{</div><div class="line">    <span class="keyword">typedef</span> <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a> value_type;</div><div class="line">    <span class="keyword">typedef</span> <span class="keywordtype">int</span> work_type;</div><div class="line">    <span class="keyword">typedef</span> <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a> channel_type;</div><div class="line">    <span class="keyword">enum</span> { channel_type = <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>, channels = 1, fmt=<span class="charliteral">&#39;u&#39;</span>, type = <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a> };</div><div class="line">};</div><div class="line">...</div><div class="line">template&lt;<span class="keyword">typename</span> _Tp&gt; DataType&lt;std::complex&lt;_Tp&gt; &gt;</div><div class="line">{</div><div class="line">    <span class="keyword">typedef</span> std::complex&lt;_Tp&gt; value_type;</div><div class="line">    <span class="keyword">typedef</span> std::complex&lt;_Tp&gt; work_type;</div><div class="line">    <span class="keyword">typedef</span> _Tp channel_type;</div><div class="line">    <span class="comment">// DataDepth is another helper trait class</span></div><div class="line">    <span class="keyword">enum</span> { <a class="code" href="../../d0/daf/group__projection.html#ga8b5e5413af41caf3f2a0bbf4cdf517a8">depth</a> = <a class="code" href="../../d7/d0e/classcv_1_1DataDepth.html#a310c72e217ddafe5496da760134a179aa7cb026110dca902585250642b85975d2">DataDepth&lt;_Tp&gt;::value</a>, channels=2,</div><div class="line">        fmt=(channels-1)*256+<a class="code" href="../../d7/d0e/classcv_1_1DataDepth.html#a310c72e217ddafe5496da760134a179aae5030288b4884074c6dd94c287ab31ba">DataDepth&lt;_Tp&gt;::fmt</a>,</div><div class="line">        type=<a class="code" href="../../d1/d1b/group__core__hal__interface.html#gab2ebca36079fd923483abee99d7ff40d">CV_MAKETYPE</a>(<a class="code" href="../../d0/daf/group__projection.html#ga8b5e5413af41caf3f2a0bbf4cdf517a8">depth</a>, channels) };</div><div class="line">};</div><div class="line">...</div></div><!-- fragment --><p> The main purpose of this class is to convert compilation-time type information to an OpenCV-compatible data type identifier, for example: </p><div class="fragment"><div class="line"><span class="comment">// allocates a 30x40 floating-point matrix</span></div><div class="line">Mat A(30, 40, DataType&lt;float&gt;::type);</div><div class="line"></div><div class="line">Mat B = Mat_&lt;std::complex&lt;double&gt; &gt;(3, 3);</div><div class="line"><span class="comment">// the statement below will print 6, 2 , that is depth == CV_64F, channels == 2</span></div><div class="line">cout &lt;&lt; B.depth() &lt;&lt; <span class="stringliteral">&quot;, &quot;</span> &lt;&lt; B.channels() &lt;&lt; endl;</div></div><!-- fragment --><p> So, such traits are used to tell OpenCV which data type you are working with, even if such a type is not native to OpenCV. For example, the matrix B initialization above is compiled because OpenCV defines the proper specialized template class <a class="el" href="../../d0/d3a/classcv_1_1DataType.html" title="Template &quot;trait&quot; class for OpenCV primitive data types. ">DataType</a>&lt;complex&lt;_Tp&gt; &gt; . This mechanism is also useful (and used in OpenCV this way) for generic algorithms implementations.</p>
<dl class="section note"><dt>Note</dt><dd>Default values were dropped to stop confusing developers about using of unsupported types (see #7599) </dd></dl>
</div><hr/>The documentation for this class was generated from the following file:<ul>
<li>opencv2/core/<a class="el" href="../../d9/deb/modules_2core_2include_2opencv2_2core_2traits_8hpp.html">traits.hpp</a></li>
</ul>
</div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:42 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
